
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        2/16/2009
 * PROJECT:             MCWEBSITE
 * PURPOSE:             websiteNewsCategoryDAL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Web.Configuration;
using MCWEBSITE.ENTITY;

namespace MCWEBSITE.DAL
{
    public class websiteNewsCategoryDAL
    {
        #region  Properties

        public static string FIELD_CATEGORYID = "CategoryID";
        public static string FIELD_LANGUAGECODE = "LanguageCode";
        public static string FIELD_CATEGORYCODE = "CategoryCode";
        public static string FIELD_CATEGORYNAME = "CategoryName";
        public static string FIELD_DESCRIPTION = "Description";
        public static string FIELD_PARENTCATEGORYID = "ParentCategoryID";
        public static string FIELD_ATRIBUTE1 = "Atribute1";
        public static string FIELD_ATRIBUTE2 = "Atribute2";
        public static string FIELD_ATRIBUTE3 = "Atribute3";
        public static string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ContentConnectionString"].ToString();

        #endregion

        #region Protected methods

        /// <summary>
        /// Select entity of websiteNewsCategory
        /// </summary>
        /// <param name="CategoryID">Primary Keys</param>
        /// <returns>Collection of websiteNewsCategoryInfo</returns>
        public static websiteNewsCategoryInfo SelectOne(int CategoryID)
        {
            websiteNewsCategoryInfo _websiteNewsCategoryInfo = new websiteNewsCategoryInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteNewsCategorySelectOne", CategoryID);
                if (dr.Read())
                    setwebsiteNewsCategoryInfo(dr, ref _websiteNewsCategoryInfo);
                return _websiteNewsCategoryInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="LanguageCode"></param>
        /// <returns></returns>
        public static List<websiteNewsCategoryInfo> SelectAllParent()
        {
            List<websiteNewsCategoryInfo> lstwebsiteNewsCategory = new List<websiteNewsCategoryInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteParentNewsCategorySelectAll");
                setListwebsiteNewsCategoryInfo(ref dr, ref lstwebsiteNewsCategory);
                return lstwebsiteNewsCategory;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="LanguageCode"></param>
        /// <returns></returns>
        public static List<websiteNewsCategoryInfo> SelectParentByLanguageCode(string LanguageCode)
        {
            List<websiteNewsCategoryInfo> lstwebsiteNewsCategory = new List<websiteNewsCategoryInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteParentNewsCategorySelectByLanguageCode", LanguageCode);
                setListwebsiteNewsCategoryInfo(ref dr, ref lstwebsiteNewsCategory);
                return lstwebsiteNewsCategory;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="LanguageCode"></param>
        /// <param name="CategoryID"></param>
        /// <returns></returns>
        public static List<websiteNewsCategoryInfo> SelectCategoryByLangAndParent(string LanguageCode, string CategoryID)
        {
            List<websiteNewsCategoryInfo> lstwebsiteNewsCategory = new List<websiteNewsCategoryInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteNewsCategorySelectByLangAndParent", LanguageCode, CategoryID);
                setListwebsiteNewsCategoryInfo(ref dr, ref lstwebsiteNewsCategory);
                return lstwebsiteNewsCategory;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select all websiteNewsCategory
        /// </summary>
        /// <returns>Collection of websiteNewsCategoryInfo</returns>
        public static List<websiteNewsCategoryInfo> SelectAll()
        {
            List<websiteNewsCategoryInfo> lstwebsiteNewsCategory = new List<websiteNewsCategoryInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteNewsCategorySelectAll");
                setListwebsiteNewsCategoryInfo(ref dr, ref lstwebsiteNewsCategory);
                return lstwebsiteNewsCategory;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select
        /// </summary>
        /// <param name="websiteNewsCategorynfo">Modify this method adapting your need</param>
        /// <returns>Collection of websiteNewsCategoryInfo</returns>
        public static List<websiteNewsCategoryInfo> SelectFilters()
        {
            string criterias = string.Empty;
            List<websiteNewsCategoryInfo> lstwebsiteNewsCategory = new List<websiteNewsCategoryInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteNewsCategorySelectByFilters");
                setListwebsiteNewsCategoryInfo(ref dr, ref lstwebsiteNewsCategory);
                return lstwebsiteNewsCategory;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Insert websiteNewsCategory
        /// </summary>
        /// <param name="websiteNewsCategoryInfo">Entity of websiteNewsCategory</param>
        /// <returns>error code</returns>
        public static int Insert(websiteNewsCategoryInfo _websiteNewsCategoryInfo)
        {
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteNewsCategoryInsert"
                                            , _websiteNewsCategoryInfo.CategoryID
                                            , _websiteNewsCategoryInfo.LanguageCode
                                            , _websiteNewsCategoryInfo.CategoryCode
                                            , _websiteNewsCategoryInfo.CategoryName
                                            , _websiteNewsCategoryInfo.Description
                                            , _websiteNewsCategoryInfo.ParentCategoryID
                                            , _websiteNewsCategoryInfo.Atribute1
                                            , _websiteNewsCategoryInfo.Atribute2
                                            , _websiteNewsCategoryInfo.Atribute3
                                            );
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Update websiteNewsCategory
        /// </summary>
        /// <param name="websiteNewsCategoryInfo">Entity of websiteNewsCategory</param>
        /// <returns>error code</returns>
        public static int Update(websiteNewsCategoryInfo _websiteNewsCategoryInfo)
        {
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteNewsCategoryUpdate"
                                            , _websiteNewsCategoryInfo.CategoryID
                                            , _websiteNewsCategoryInfo.LanguageCode
                                            , _websiteNewsCategoryInfo.CategoryCode
                                            , _websiteNewsCategoryInfo.CategoryName
                                            , _websiteNewsCategoryInfo.Description
                                            , _websiteNewsCategoryInfo.ParentCategoryID
                                            , _websiteNewsCategoryInfo.Atribute1
                                            , _websiteNewsCategoryInfo.Atribute2
                                            , _websiteNewsCategoryInfo.Atribute3
                                            );
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Delete SchoolAdmin
        /// </summary>
        /// <param name="CategoryID">Primary Key</param>
        /// <returns>error code</returns>
        public static int Delete(int CategoryID)
        {
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteNewsCategoryDelete", CategoryID);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        #endregion

        #region "Utilities method"

        private static void setListwebsiteNewsCategoryInfo(ref SqlDataReader dr, ref List<websiteNewsCategoryInfo> lstwebsiteNewsCategory)
        {
            websiteNewsCategoryInfo _websiteNewsCategoryInfo = null;
            while (dr.Read())
            {
                _websiteNewsCategoryInfo = new websiteNewsCategoryInfo();
                setwebsiteNewsCategoryInfo(dr, ref _websiteNewsCategoryInfo);
                lstwebsiteNewsCategory.Add(_websiteNewsCategoryInfo);
            }
        }

        private static void setwebsiteNewsCategoryInfo(SqlDataReader dr, ref websiteNewsCategoryInfo _websiteNewsCategoryInfo)
        {
            _websiteNewsCategoryInfo.CategoryID = dr[websiteNewsCategoryDAL.FIELD_CATEGORYID] != DBNull.Value ? Convert.ToInt32(dr[websiteNewsCategoryDAL.FIELD_CATEGORYID]) : 0;
            _websiteNewsCategoryInfo.LanguageCode = dr[websiteNewsCategoryDAL.FIELD_LANGUAGECODE] != DBNull.Value ? Convert.ToString(dr[websiteNewsCategoryDAL.FIELD_LANGUAGECODE]) : string.Empty;
            _websiteNewsCategoryInfo.CategoryCode = dr[websiteNewsCategoryDAL.FIELD_CATEGORYCODE] != DBNull.Value ? Convert.ToString(dr[websiteNewsCategoryDAL.FIELD_CATEGORYCODE]) : string.Empty;
            _websiteNewsCategoryInfo.CategoryName = dr[websiteNewsCategoryDAL.FIELD_CATEGORYNAME] != DBNull.Value ? Convert.ToString(dr[websiteNewsCategoryDAL.FIELD_CATEGORYNAME]) : string.Empty;
            _websiteNewsCategoryInfo.Description = dr[websiteNewsCategoryDAL.FIELD_DESCRIPTION] != DBNull.Value ? Convert.ToString(dr[websiteNewsCategoryDAL.FIELD_DESCRIPTION]) : string.Empty;
            _websiteNewsCategoryInfo.ParentCategoryID = dr[websiteNewsCategoryDAL.FIELD_PARENTCATEGORYID] != DBNull.Value ? Convert.ToInt32(dr[websiteNewsCategoryDAL.FIELD_PARENTCATEGORYID]) : 0;
            _websiteNewsCategoryInfo.Atribute1 = dr[websiteNewsCategoryDAL.FIELD_ATRIBUTE1] != DBNull.Value ? Convert.ToString(dr[websiteNewsCategoryDAL.FIELD_ATRIBUTE1]) : string.Empty;
            _websiteNewsCategoryInfo.Atribute2 = dr[websiteNewsCategoryDAL.FIELD_ATRIBUTE2] != DBNull.Value ? Convert.ToString(dr[websiteNewsCategoryDAL.FIELD_ATRIBUTE2]) : string.Empty;
            _websiteNewsCategoryInfo.Atribute3 = dr[websiteNewsCategoryDAL.FIELD_ATRIBUTE3] != DBNull.Value ? Convert.ToString(dr[websiteNewsCategoryDAL.FIELD_ATRIBUTE3]) : string.Empty;

        }
        #endregion Methods

        #region Private Members

        private static string TABLE_NAME = "[mc_websiteNewsCategory]";

        #endregion
    }
}

